﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class AnnotationPoolTests
    {
        [TestMethod]
        public void ShouldAddAndRetreiveValue()
        {
            AnnotationPool pool = new AnnotationPool();
            pool.Add("abc", null);
            var poolItem = pool["abc"];

            Assert.AreEqual("abc", poolItem.Value);
            Assert.IsNull(poolItem.ParentValue);
        }

        [TestMethod]
        public void ShouldReturnNullIfValueNotFound()
        {
            AnnotationPool pool = new AnnotationPool();
            Assert.IsNull(pool["notFound"]);
        }

        [TestMethod]
        public void ShouldReturnNullIfValueNull()
        {
            AnnotationPool pool = new AnnotationPool();
            Assert.IsNull(pool[null]);
        }

        [TestMethod]
        public void ShouldGetItemByParent()
        {
            AnnotationPool pool = new AnnotationPool();
            pool.Add(1, new AnnotationValue(AnnotationKey.SnpName, "rs001"));
            pool.Add(2, new AnnotationValue(AnnotationKey.SnpName, "rs002"));

            var item = pool.GetForParent(new AnnotationValue(AnnotationKey.SnpName, "rs001"));
            Assert.AreEqual(1, item.Value);
        }

        [TestMethod]
        public void ShouldReturnNullIfParentNotFound()
        {
            AnnotationPool pool = new AnnotationPool();
            pool.Add(1, null);

            var item = pool.GetForParent(new AnnotationValue(AnnotationKey.SnpName, "rs001"));
            Assert.IsNull(item);
        }
    }
}
